﻿using UnityEngine;

public class BorderPointSetting : MonoBehaviour
{
    //[Header("使用CInemachineSmoothPath脚本")]
    //public CinemachineSmoothPath csp;
    [Header("使用Border脚本")]
    public Border bd;
    [Header("点击下面导入按钮后，会清除Border节点下的cube，并跟进新的节点生成新的Cube")]
    public string points = "";

    public void SetBorderPoint()
    {
        DestroyChild(bd.gameObject);
        bd.Vertices.Clear();
        bd.VerticesPos.Clear();
        Vector3 lastPoint = Vector3.zero;
        //for (int i = 0; i < csp.m_Waypoints.Length; i++)
        //{
        //    bd.Vertices.Add(i);
        //    Vector4 waypoint = csp.m_Waypoints[i].AsVector4;
        //    Vector3 cspPos = csp.transform.position;
        //    Vector3 point = new Vector3(waypoint.x + cspPos.x, waypoint.y + cspPos.y, waypoint.z + cspPos.z);
        //    bd.VerticesPos.Add(point);
        //    if (i != 0)
        //    {
        //        bd.CreateCube((i - 1).ToString(), point, lastPoint);
        //        if (i == csp.m_Waypoints.Length - 1)
        //        {
        //            Vector3 cspPoszero = bd.VerticesPos[0];
        //            bd.CreateCube((i).ToString(), point, cspPoszero);
        //        }
        //    }
        //    lastPoint = point;

        //}
        Debug.Log("边界点配置导入成功！");
    }

    void DestroyChild(GameObject go)
    {
        Debug.Log(go.transform.childCount);
        int count = go.transform.childCount;
        while (go.transform.childCount > 0)
        {
            Debug.Log(go.transform.GetChild(0).name);
            DestroyImmediate(go.transform.GetChild(0).gameObject);
        }
    }

}
